//
//  WSqlite.m
//  CPICApp
//
//  Created by sinosoft on 13-4-24.
//  Copyright (c) 2013年 lizhiwei. All rights reserved.
//

#import "WSqlite.h"

static sqlite3 *database;
static WSqlite *instance = nil;

@implementation WSqlite

+(WSqlite*)Instance
{
	
	
	@synchronized(self){
		if (instance == nil) {
			instance = [[WSqlite alloc] init];
		}
	}
	return instance;
}

-(BOOL)openSqlite
{
	if (sqlite3_open(filePath,&database) != SQLITE_OK)
	{
		sqlite3_close(database);
		NSLog(@"openning faild!");
		return 0;
	}
	return 1;
}

-(id)init
{
    if (self=[super init])
	{
        dataBaseName=@"cpicDB";
        
        NSString*tempFilePath=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
        tempFilePath=[tempFilePath stringByAppendingPathComponent:dataBaseName];
        
		filePath=[[tempFilePath stringByAppendingString:@".sqlite"]UTF8String];
        
        NSFileManager *fm = [NSFileManager defaultManager];
        
        if(![fm fileExistsAtPath:[NSString stringWithUTF8String:filePath]]){
            NSString *pathInBundle = [[NSBundle mainBundle] pathForResource:@"cpicDB" ofType:@"sqlite"];
            NSError *error;
            [fm copyItemAtPath:pathInBundle toPath:[NSString stringWithUTF8String:filePath] error:&error];
        }
        
		
		if (![self openSqlite]) return nil;
        
	}
	return self;
}

-(BOOL)insertServiceType:(NSString *)strServiceType serviceName:(NSString *)strServiceName
{
    if (strServiceType.length==0) {
        NSLog(@"strServiceType lent=0");
        return 0;
    }
    NSString *serviceTypeTable=@"SERVICENET_TYPE";
    sqlite3_stmt *statement;
    NSString *replace = [NSString stringWithFormat:@"INSERT INTO %@ (serverType,serverName) VALUES (?,?)",serviceTypeTable];
    if (sqlite3_prepare_v2(database, [replace UTF8String], -1, &statement, nil)== SQLITE_OK)
    {
        sqlite3_bind_text(statement,1,[strServiceType UTF8String],-1,NULL);
        sqlite3_bind_text(statement,2,[strServiceType UTF8String],-1,NULL);
    }
    NSLog(@"%d",sqlite3_step(statement));
    return 1;
}

-(BOOL)insertServicePoint:(NSArray *)arrServicePoint
{
    if (!arrServicePoint)
	{
		NSLog(@"empty arrServicePoint!");
		return 0;
		if (![arrServicePoint count])
		{
			NSLog(@"illegal arrServicePoint!");
			return 0;
		}
	}
    if ([arrServicePoint count]<=0) {
        return 0;
    }
    NSLog(@"要插入的数据为:%@",arrServicePoint);
    for (int i=0; i<[arrServicePoint count]; i++) {
        NSMutableDictionary *dictItem=[arrServicePoint objectAtIndex:i];
        NSString *strServerType;
        if ([dictItem valueForKey:@"serverType"]) {
            strServerType=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"serverType"]];
        }else{
            strServerType=@"";
        }
        NSString *strBrand;
        if ([dictItem valueForKey:@"brand"]) {
            strBrand=[dictItem valueForKey:@"brand"];
        }else
        {
            strBrand=@"";
        }
//        if ([self CheckHasServiceType:strServerType])
//        {
            if ([self deleteServiceType2:strServerType withBrand:strBrand]) {
                NSLog(@"删除数据成功!");
                   }
            else
            {
                NSLog(@"删除数据失败!");
            }
//        }
    }
    for (int i=0; i<[arrServicePoint count]; i++) {
        NSMutableDictionary *dictItem=[arrServicePoint objectAtIndex:i];
        NSString *strId,*strServerType,*strServerName,*strBrand,*strSupport,*strPhoneNo,*strAddress,*strPosition,*strPromotionstype,*strPromotions,*strPartner,*strExponent;
        if ([dictItem valueForKey:@"id"]) {
            strId=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"id"]];
        }else{
            strId=@"";
        }
        
        if ([dictItem valueForKey:@"serverType"]) {
            strServerType=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"serverType"]];
        }else{
            strServerType=@"";
        }
        
        if ([dictItem valueForKey:@"name"]) {
            strServerName=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"name"]];
        }else{
            strServerName=@"";
        }
        
        if ([dictItem valueForKey:@"brand"]) {
            strBrand=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"brand"]];
        }else{
            strBrand=@"";
        }
        
        if ([dictItem valueForKey:@"support"]) {
            strSupport=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"support"]];
        }else{
            strSupport=@"";
        }
        
        if ([dictItem valueForKey:@"phoneNo"]) {
            strPhoneNo=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"phoneNo"]];
        }else{
            strPhoneNo=@"";
        }
        
        if ([dictItem valueForKey:@"address"]) {
            strAddress=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"address"]];
        }else{
            strAddress=@"";
        }
        if ([dictItem valueForKey:@"position"]) {
            strPosition=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"position"]];
        }else{
            strPosition=@"";
        }
        
        if ([dictItem valueForKey:@"promotionstype"]) {
            strPromotionstype=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"promotionstype"]];
        }else{
            strPromotionstype=@"";
        }
        
        if ([dictItem valueForKey:@"promotions"]) {
           strPromotions=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"promotions"]];
        }else{
            strPromotions=@"";
        }
        if ([dictItem valueForKey:@"partner"]) {
            strPartner=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"partner"]];
        }else{
            strPartner=@"";
        }
        
        if ([dictItem valueForKey:@"exponent"]) {
            strExponent=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"exponent"]];
        }else{
            strExponent=@"";
        }
        
        
        NSString *servicePointTable=@"SERVICE_POINT";
        sqlite3_stmt *statement;
        if ([self CheckHasServiceType:strServerType]) {
         /*   NSString *updateStr = [NSString stringWithFormat:@"update %@ set id ='%@',serverType='%@',serverName='%@',brand='%@',support='%@',phoneNo='%@',address='%@',position='%@',promotionstype='%@', promotions='%@',partner='%@',exponent='%@' where serverType='%@'",servicePointTable,strId,strServerType,strServerName,strBrand,strSupport,strPhoneNo,strAddress,strPosition,strPromotionstype,strPromotions,strPartner,strExponent,strServerType];
            NSLog(@"sql:%@",updateStr);
            if (sqlite3_exec(database, [updateStr UTF8String], NULL, NULL, NULL)!= SQLITE_OK)
            {
                NSLog(@"修改标注点信息失败");
            }
            else
            {
                NSLog(@"修改标注点信息成功");
            }
          */
//            if ([self deleteServiceType:strServerType]) {
//                NSLog(@"删除数据成功!");
                NSString *replace = [NSString stringWithFormat:@"INSERT INTO %@ (id,serverType,serverName,brand,support,phoneNo,address,position,promotionstype,promotions,partner,exponent) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)",servicePointTable];
                if (sqlite3_prepare_v2(database, [replace UTF8String], -1, &statement, nil)== SQLITE_OK)
                {
                    sqlite3_bind_text(statement,1,[strId UTF8String],-1,NULL);
                    sqlite3_bind_text(statement,2,[strServerType UTF8String],-1,NULL);
                    sqlite3_bind_text(statement,3,[strServerName UTF8String],-1,NULL);
                    sqlite3_bind_text(statement,4,[strBrand UTF8String],-1,NULL);
                    sqlite3_bind_text(statement,5,[strSupport UTF8String],-1,NULL);
                    sqlite3_bind_text(statement,6,[strPhoneNo UTF8String],-1,NULL);
                    sqlite3_bind_text(statement,7,[strAddress UTF8String],-1,NULL);
                    sqlite3_bind_text(statement,8,[strPosition UTF8String],-1,NULL);
                    sqlite3_bind_text(statement,9,[strPromotionstype UTF8String],-1,NULL);
                    sqlite3_bind_text(statement,10,[strPromotions UTF8String],-1,NULL);
                    sqlite3_bind_text(statement,11,[strPartner UTF8String],-1,NULL);
                    sqlite3_bind_text(statement,12,[strExponent UTF8String],-1,NULL);
                    
                }
                NSLog(@"%d",sqlite3_step(statement));
                
//            }
//            else
//            {
//                NSLog(@"删除数据失败!");
//            }
        }
        else
        {
            NSString *replace = [NSString stringWithFormat:@"INSERT INTO %@ (id,serverType,serverName,brand,support,phoneNo,address,position,promotionstype,promotions,partner,exponent) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)",servicePointTable];
            if (sqlite3_prepare_v2(database, [replace UTF8String], -1, &statement, nil)== SQLITE_OK)
            {
                sqlite3_bind_text(statement,1,[strId UTF8String],-1,NULL);
                sqlite3_bind_text(statement,2,[strServerType UTF8String],-1,NULL);
                sqlite3_bind_text(statement,3,[strServerName UTF8String],-1,NULL);
                sqlite3_bind_text(statement,4,[strBrand UTF8String],-1,NULL);
                sqlite3_bind_text(statement,5,[strSupport UTF8String],-1,NULL);
                sqlite3_bind_text(statement,6,[strPhoneNo UTF8String],-1,NULL);
                sqlite3_bind_text(statement,7,[strAddress UTF8String],-1,NULL);
                sqlite3_bind_text(statement,8,[strPosition UTF8String],-1,NULL);
                sqlite3_bind_text(statement,9,[strPromotionstype UTF8String],-1,NULL);
                sqlite3_bind_text(statement,10,[strPromotions UTF8String],-1,NULL);
                sqlite3_bind_text(statement,11,[strPartner UTF8String],-1,NULL);
                sqlite3_bind_text(statement,12,[strExponent UTF8String],-1,NULL);
                
            }
            NSLog(@"%d",sqlite3_step(statement));
            
        }
        [strId release];
        [strServerType release];
        [strServerName release];
        [strBrand release];
        [strSupport release];
        [strPhoneNo release];
        [strAddress release];
        [strPosition release];
        [strPromotionstype release];
        [strPromotions release];
        [strPartner release];
        [strExponent release];
    }
    return 1;
}

-(BOOL)insertServicePoint:(NSArray *)arrServicePoint brandCode:(NSString *)strBrandCode
{
    if (!arrServicePoint)
	{
		NSLog(@"empty arrServicePoint!");
		return 0;
		if (![arrServicePoint count])
		{
			NSLog(@"illegal arrServicePoint!");
			return 0;
		}
	}
    if ([arrServicePoint count]<=0) {
        return 0;
    }
    if (strBrandCode.length==0) {
        strBrandCode=@"";
    }
    NSLog(@"要插入的数据为:%@",arrServicePoint);
    if (strBrandCode.length!=0) {
        for (int i=0; i<[arrServicePoint count]; i++) {
            NSMutableDictionary *dictItem=[arrServicePoint objectAtIndex:i];
            NSString *strId;
            if ([dictItem valueForKey:@"id"]) {
                strId=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"id"]];
            }else{
                strId=@"";
            }
            if ([self deleteServiceRelacionBrand:strId withBrand:strBrandCode]) {
                NSLog(@"删除表SERVICE_RELACTION_BRAND数据成功!");
            }
            else
            {
                NSLog(@"删除SERVICE_RELACTION_BRAND数据失败!");
            }
        }
    }
    for (int i=0; i<[arrServicePoint count]; i++) {
        NSMutableDictionary *dictItem=[arrServicePoint objectAtIndex:i];
        NSString *strServerType;
        if ([dictItem valueForKey:@"serverType"]) {
            strServerType=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"serverType"]];
        }else{
            strServerType=@"";
        }
        NSString *strBrand,*strId;
        if ([dictItem valueForKey:@"brand"]) {
            strBrand=[dictItem valueForKey:@"brand"];
        }else
        {
            strBrand=@"";
        }
        if ([dictItem valueForKey:@"id"]) {
            strId=[dictItem valueForKey:@"id"];
        }else
        {
            strId=@"";
        }
        if ([self deleteServiceType2:strServerType withBrand:strBrand withId:strId]) {
            NSLog(@"删除表SERVICE_POINT数据成功!");
        }
        else
        {
            NSLog(@"删除表SERVICE_POINT数据失败!");
        }
    }

    for (int i=0; i<[arrServicePoint count]; i++) {
        NSMutableDictionary *dictItem=[arrServicePoint objectAtIndex:i];
        NSString *strId,*strServerType,*strServerName,*strBrand,*strSupport,*strPhoneNo,*strAddress,*strPosition,*strPromotionstype,*strPromotions,*strPartner,*strExponent;
        if ([dictItem valueForKey:@"id"]) {
            strId=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"id"]];
        }else{
            strId=@"";
        }
        
        if ([dictItem valueForKey:@"serverType"]) {
            strServerType=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"serverType"]];
        }else{
            strServerType=@"";
        }
        
        if ([dictItem valueForKey:@"name"]) {
            strServerName=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"name"]];
        }else{
            strServerName=@"";
        }
        
        if ([dictItem valueForKey:@"brand"]) {
            strBrand=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"brand"]];
        }else{
            strBrand=@"";
        }
        
        if ([dictItem valueForKey:@"support"]) {
            strSupport=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"support"]];
        }else{
            strSupport=@"";
        }
        
        if ([dictItem valueForKey:@"phoneNo"]) {
            strPhoneNo=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"phoneNo"]];
        }else{
            strPhoneNo=@"";
        }
        
        if ([dictItem valueForKey:@"address"]) {
            strAddress=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"address"]];
        }else{
            strAddress=@"";
        }
        if ([dictItem valueForKey:@"position"]) {
            strPosition=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"position"]];
        }else{
            strPosition=@"";
        }
        
        if ([dictItem valueForKey:@"promotionstype"]) {
            strPromotionstype=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"promotionstype"]];
        }else{
            strPromotionstype=@"";
        }
        
        if ([dictItem valueForKey:@"promotions"]) {
            strPromotions=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"promotions"]];
        }else{
            strPromotions=@"";
        }
        if ([dictItem valueForKey:@"partner"]) {
            strPartner=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"partner"]];
        }else{
            strPartner=@"";
        }
        
        if ([dictItem valueForKey:@"exponent"]) {
            strExponent=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"exponent"]];
        }else{
            strExponent=@"";
        }
        //begin先插入表 SERVICE_RELACTION_BRAND
        if (strBrandCode.length!=0) {
            NSString *servicePointBrandTable=@"SERVICE_RELACTION_BRAND";
            sqlite3_stmt *statement2;
            NSString *replace2 = [NSString stringWithFormat:@"INSERT INTO %@ (servicePointId,brandCode) VALUES (?,?)",servicePointBrandTable];
            if (sqlite3_prepare_v2(database, [replace2 UTF8String], -1, &statement2, nil)== SQLITE_OK)
            {
                sqlite3_bind_text(statement2,1,[strId UTF8String],-1,NULL);
                sqlite3_bind_text(statement2,2,[strBrandCode UTF8String],-1,NULL);
                
            }
            NSLog(@"表SERVICE_RELACTION_BRAND插入情况:%d",sqlite3_step(statement2));
        }

        //end
        
        
        NSString *servicePointTable=@"SERVICE_POINT";
        sqlite3_stmt *statement;
        if ([self CheckHasServiceType:strServerType]) {
            NSString *replace = [NSString stringWithFormat:@"INSERT INTO %@ (id,serverType,serverName,brand,support,phoneNo,address,position,promotionstype,promotions,partner,exponent) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)",servicePointTable];
            if (sqlite3_prepare_v2(database, [replace UTF8String], -1, &statement, nil)== SQLITE_OK)
            {
                sqlite3_bind_text(statement,1,[strId UTF8String],-1,NULL);
                sqlite3_bind_text(statement,2,[strServerType UTF8String],-1,NULL);
                sqlite3_bind_text(statement,3,[strServerName UTF8String],-1,NULL);
                sqlite3_bind_text(statement,4,[strBrand UTF8String],-1,NULL);
                sqlite3_bind_text(statement,5,[strSupport UTF8String],-1,NULL);
                sqlite3_bind_text(statement,6,[strPhoneNo UTF8String],-1,NULL);
                sqlite3_bind_text(statement,7,[strAddress UTF8String],-1,NULL);
                sqlite3_bind_text(statement,8,[strPosition UTF8String],-1,NULL);
                sqlite3_bind_text(statement,9,[strPromotionstype UTF8String],-1,NULL);
                sqlite3_bind_text(statement,10,[strPromotions UTF8String],-1,NULL);
                sqlite3_bind_text(statement,11,[strPartner UTF8String],-1,NULL);
                sqlite3_bind_text(statement,12,[strExponent UTF8String],-1,NULL);
                
            }
            NSLog(@"%d",sqlite3_step(statement));
            
        }
        else
        {
            NSString *replace = [NSString stringWithFormat:@"INSERT INTO %@ (id,serverType,serverName,brand,support,phoneNo,address,position,promotionstype,promotions,partner,exponent) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)",servicePointTable];
            if (sqlite3_prepare_v2(database, [replace UTF8String], -1, &statement, nil)== SQLITE_OK)
            {
                sqlite3_bind_text(statement,1,[strId UTF8String],-1,NULL);
                sqlite3_bind_text(statement,2,[strServerType UTF8String],-1,NULL);
                sqlite3_bind_text(statement,3,[strServerName UTF8String],-1,NULL);
                sqlite3_bind_text(statement,4,[strBrand UTF8String],-1,NULL);
                sqlite3_bind_text(statement,5,[strSupport UTF8String],-1,NULL);
                sqlite3_bind_text(statement,6,[strPhoneNo UTF8String],-1,NULL);
                sqlite3_bind_text(statement,7,[strAddress UTF8String],-1,NULL);
                sqlite3_bind_text(statement,8,[strPosition UTF8String],-1,NULL);
                sqlite3_bind_text(statement,9,[strPromotionstype UTF8String],-1,NULL);
                sqlite3_bind_text(statement,10,[strPromotions UTF8String],-1,NULL);
                sqlite3_bind_text(statement,11,[strPartner UTF8String],-1,NULL);
                sqlite3_bind_text(statement,12,[strExponent UTF8String],-1,NULL);
                
            }
            NSLog(@"%d",sqlite3_step(statement));
            
        }
        [strId release];
        [strServerType release];
        [strServerName release];
        [strBrand release];
        [strSupport release];
        [strPhoneNo release];
        [strAddress release];
        [strPosition release];
        [strPromotionstype release];
        [strPromotions release];
        [strPartner release];
        [strExponent release];
    }
    return 1;
}
-(BOOL)CheckHasServiceType:(NSString *)strServiceType
{
    if (strServiceType.length==0) {
        NSLog(@"ServiceType length=0");
        return 0;
    }
    NSString *servicePointTable=@"SERVICE_POINT";
    sqlite3_stmt *statement;
    NSString *select = [NSString stringWithFormat:@"SELECT serverType FROM %@ WHERE serverType='%@'",servicePointTable,strServiceType];
    if (sqlite3_prepare_v2(database, [select UTF8String], -1, &statement, nil)!= SQLITE_OK)
    {
        sqlite3_close(database);
        NSAssert1(0, @"Error querying: %s", err);
    }
    while (sqlite3_step(statement)==SQLITE_ROW)
    {
        char *ss=(char*)sqlite3_column_text(statement, 0);
        if (ss!=NULL) {
            return TRUE;
            
        }
        else
        {
            return FALSE;
        }
        sqlite3_finalize(statement);
    }
    return FALSE;
}
-(BOOL)deleteServiceType:(NSString *)strServiceType
{
    NSString *tableDelete=@"SERVICE_POINT";
    NSString *sqlDelete=[NSString stringWithFormat:@"delete from %@ where serverType='%@'",tableDelete,strServiceType];
	sqlite3_stmt *statement;
	
	int linkCode = sqlite3_prepare_v2(database, [sqlDelete UTF8String], [sqlDelete length], &statement, NULL);
	if (linkCode != SQLITE_OK) {
		return NO;
	}
	linkCode = sqlite3_step(statement);
	sqlite3_finalize(statement);
	if (linkCode != SQLITE_DONE) {
		return NO;
	}
	return YES;
}

-(BOOL)deleteServiceType2:(NSString *)strServiceType withBrand:(NSString *)strBrand
{
    NSString *tableDelete=@"SERVICE_POINT";
    NSString *sqlDelete=[NSString stringWithFormat:@"delete from %@ where serverType='%@' and brand='%@'",tableDelete,strServiceType,strBrand];
	sqlite3_stmt *statement;
	
	int linkCode = sqlite3_prepare_v2(database, [sqlDelete UTF8String], [sqlDelete length], &statement, NULL);
	if (linkCode != SQLITE_OK) {
		return NO;
	}
	linkCode = sqlite3_step(statement);
	sqlite3_finalize(statement);
	if (linkCode != SQLITE_DONE) {
		return NO;
	}
	return YES;
}
-(BOOL)deleteServiceType2:(NSString *)strServiceType withBrand:(NSString *)strBrand withId:(NSString *)strId
{
    NSString *tableDelete=@"SERVICE_POINT";
    NSString *sqlDelete=[NSString stringWithFormat:@"delete from %@ where serverType='%@' and brand='%@' and id='%@'",tableDelete,strServiceType,strBrand,strId];
	sqlite3_stmt *statement;
	
	int linkCode = sqlite3_prepare_v2(database, [sqlDelete UTF8String], [sqlDelete length], &statement, NULL);
	if (linkCode != SQLITE_OK) {
		return NO;
	}
	linkCode = sqlite3_step(statement);
	sqlite3_finalize(statement);
	if (linkCode != SQLITE_DONE) {
		return NO;
	}
	return YES;
}
-(BOOL)deleteServiceRelacionBrand:(NSString *)strServicePointId withBrand:(NSString *)strBrandCode
{
    NSString *tableDelete=@"SERVICE_RELACTION_BRAND";
    NSString *sqlDelete=[NSString stringWithFormat:@"delete from %@ where servicePointId='%@' and brandCode='%@'",tableDelete,strServicePointId,strBrandCode];
	sqlite3_stmt *statement;
	
	int linkCode = sqlite3_prepare_v2(database, [sqlDelete UTF8String], [sqlDelete length], &statement, NULL);
	if (linkCode != SQLITE_OK) {
		return NO;
	}
	linkCode = sqlite3_step(statement);
	sqlite3_finalize(statement);
	if (linkCode != SQLITE_DONE) {
		return NO;
	}
	return YES;
}
-(NSMutableArray *)getServicePoint
{
    NSString *servicePointTable=@"SERVICE_POINT";
    sqlite3_stmt *statement;
    NSString *select = [NSString stringWithFormat:@"SELECT * FROM %@",servicePointTable];
    NSMutableArray *arrSerice=[[NSMutableArray alloc]init];
    if(sqlite3_prepare_v2(database, [select UTF8String], -1, &statement, nil)!=SQLITE_OK)
    {
        sqlite3_close(database);
        NSAssert(0,@"Error querying:%s", err);
    }
    while (sqlite3_step(statement)==SQLITE_ROW)
    {
        
        NSString *strId=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 0)];
        NSString *strServerType=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 1)];
        NSString *strServerName=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 2)];
        NSString *strBrand=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 3)];
        NSString *strSupport=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 4)];
        NSString *strPhoneNo=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 5)];
        NSString *strAddress=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 6)];
        NSString *strPosition=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 7)];
        NSString *strPromotionstype=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 8)];
        NSString *strPromotions=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 9)];
        NSString *strPartner=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 10)];
        NSString *strExponent=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 11)];
        
        NSMutableDictionary *dictService=[[NSMutableDictionary alloc]init];
        [dictService setObject:strId forKey:@"id"];
        [dictService setObject:strServerType forKey:@"serverType"];
        [dictService setObject:strServerName forKey:@"serverName"];
        [dictService setObject:strBrand forKey:@"brand"];
        [dictService setObject:strSupport forKey:@"support"];
        [dictService setObject:strPhoneNo forKey:@"phoneNo"];
        [dictService setObject:strAddress forKey:@"address"];
        [dictService setObject:strPosition forKey:@"position"];
        [dictService setObject:strPromotionstype forKey:@"promotionstype"];
        [dictService setObject:strPromotions forKey:@"promotions"];
        [dictService setObject:strPartner forKey:@"partner"];
        [dictService setObject:strExponent forKey:@"exponent"];
        [arrSerice addObject:dictService];
        [dictService release];
    }
    NSLog(@"sqlite:count-%d",[arrSerice count]);
    NSLog(@"sqlite:arrSerice%@",arrSerice);
    return arrSerice;
}

-(NSMutableArray *)getServiceSpecifyPoint:(NSString *)strServiceType
{
    NSString *servicePointTable=@"SERVICE_POINT";
    sqlite3_stmt *statement;
    NSString *select = [NSString stringWithFormat:@"SELECT * FROM %@ WHERE serverType='%@'",servicePointTable,strServiceType];
    NSMutableArray *arrSerice=[[NSMutableArray alloc]init];
    if(sqlite3_prepare_v2(database, [select UTF8String], -1, &statement, nil)!=SQLITE_OK)
    {
        sqlite3_close(database);
        NSAssert(0,@"Error querying:%s", err);
    }
    while (sqlite3_step(statement)==SQLITE_ROW)
    {
        
        NSString *strId=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 0)];
        NSString *strServerType=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 1)];
        NSString *strServerName=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 2)];
        NSString *strBrand=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 3)];
        NSString *strSupport=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 4)];
        NSString *strPhoneNo=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 5)];
        NSString *strAddress=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 6)];
        NSString *strPosition=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 7)];
        NSString *strPromotionstype=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 8)];
        NSString *strPromotions=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 9)];
        NSString *strPartner=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 10)];
        NSString *strExponent=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 11)];
        
        NSMutableDictionary *dictService=[[NSMutableDictionary alloc]init];
        [dictService setObject:strId forKey:@"id"];
        [dictService setObject:strServerType forKey:@"serverType"];
        [dictService setObject:strServerName forKey:@"name"];
        [dictService setObject:strBrand forKey:@"brand"];
        [dictService setObject:strSupport forKey:@"support"];
        [dictService setObject:strPhoneNo forKey:@"phoneNo"];
        [dictService setObject:strAddress forKey:@"address"];
        [dictService setObject:strPosition forKey:@"position"];
        [dictService setObject:strPromotionstype forKey:@"promotionstype"];
        [dictService setObject:strPromotions forKey:@"promotions"];
        [dictService setObject:strPartner forKey:@"partner"];
        [dictService setObject:strExponent forKey:@"exponent"];
        [arrSerice addObject:dictService];
        [dictService release];
    }
    NSLog(@"sqlite:arrSerice%@",arrSerice);
    NSLog(@"arrSericeCOUNT:%d",arrSerice.count);
    return arrSerice;

}

-(NSMutableArray *)getServiceSpecifyPoint2:(NSString *)strServiceType withBrand:(NSString *)strBrand
{
    NSString *servicePointTable=@"SERVICE_POINT";
    sqlite3_stmt *statement;
    if (strBrand.length==0) {
        strBrand=@"";
    }
    NSString *select = [NSString stringWithFormat:@"SELECT * FROM %@ WHERE serverType='%@' and brand='%@'",servicePointTable,strServiceType,strBrand];
    NSMutableArray *arrSerice=[[NSMutableArray alloc]init];
    if(sqlite3_prepare_v2(database, [select UTF8String], -1, &statement, nil)!=SQLITE_OK)
    {
        sqlite3_close(database);
        NSAssert(0,@"Error querying:%s", err);
    }
    while (sqlite3_step(statement)==SQLITE_ROW)
    {
        
        NSString *strId=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 0)];
        NSString *strServerType=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 1)];
        NSString *strServerName=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 2)];
        NSString *strBrand=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 3)];
        NSString *strSupport=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 4)];
        NSString *strPhoneNo=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 5)];
        NSString *strAddress=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 6)];
        NSString *strPosition=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 7)];
        NSString *strPromotionstype=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 8)];
        NSString *strPromotions=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 9)];
        NSString *strPartner=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 10)];
        NSString *strExponent=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 11)];
        
        NSMutableDictionary *dictService=[[NSMutableDictionary alloc]init];
        [dictService setObject:strId forKey:@"id"];
        [dictService setObject:strServerType forKey:@"serverType"];
        [dictService setObject:strServerName forKey:@"name"];
        [dictService setObject:strBrand forKey:@"brand"];
        [dictService setObject:strSupport forKey:@"support"];
        [dictService setObject:strPhoneNo forKey:@"phoneNo"];
        [dictService setObject:strAddress forKey:@"address"];
        [dictService setObject:strPosition forKey:@"position"];
        [dictService setObject:strPromotionstype forKey:@"promotionstype"];
        [dictService setObject:strPromotions forKey:@"promotions"];
        [dictService setObject:strPartner forKey:@"partner"];
        [dictService setObject:strExponent forKey:@"exponent"];
        [arrSerice addObject:dictService];
        [dictService release];
    }
    NSLog(@"sqlite:arrSerice%@",arrSerice);
    NSLog(@"arrSericeCOUNT:%d",arrSerice.count);
    return arrSerice;
}
-(NSMutableArray *)getServiceBrandPoint:(NSString *)strServiceType withBrand:(NSString *)strBrand
{
    NSString *servicePointTable=@"SERVICE_POINT";
    sqlite3_stmt *statement;
    if (strBrand.length==0) {
        strBrand=@"";
    }
     NSMutableArray *arrSerice=[[NSMutableArray alloc]init];
    if (strBrand.length==0) {
        NSString *select = [NSString stringWithFormat:@"SELECT * FROM %@ WHERE serverType='%@' and brand='%@'",servicePointTable,strServiceType,strBrand];
        if(sqlite3_prepare_v2(database, [select UTF8String], -1, &statement, nil)!=SQLITE_OK)
        {
            sqlite3_close(database);
            NSAssert(0,@"Error querying:%s", err);
        }
        while (sqlite3_step(statement)==SQLITE_ROW)
        {
            
            NSString *strId=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 0)];
            NSString *strServerType=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 1)];
            NSString *strServerName=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 2)];
            NSString *strBrand=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 3)];
            NSString *strSupport=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 4)];
            NSString *strPhoneNo=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 5)];
            NSString *strAddress=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 6)];
            NSString *strPosition=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 7)];
            NSString *strPromotionstype=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 8)];
            NSString *strPromotions=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 9)];
            NSString *strPartner=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 10)];
            NSString *strExponent=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 11)];
            
            NSMutableDictionary *dictService=[[NSMutableDictionary alloc]init];
            [dictService setObject:strId forKey:@"id"];
            [dictService setObject:strServerType forKey:@"serverType"];
            [dictService setObject:strServerName forKey:@"name"];
            [dictService setObject:strBrand forKey:@"brand"];
            [dictService setObject:strSupport forKey:@"support"];
            [dictService setObject:strPhoneNo forKey:@"phoneNo"];
            [dictService setObject:strAddress forKey:@"address"];
            [dictService setObject:strPosition forKey:@"position"];
            [dictService setObject:strPromotionstype forKey:@"promotionstype"];
            [dictService setObject:strPromotions forKey:@"promotions"];
            [dictService setObject:strPartner forKey:@"partner"];
            [dictService setObject:strExponent forKey:@"exponent"];
            [arrSerice addObject:dictService];
            [dictService release];
        }
        NSLog(@"sqlite:arrSerice%@",arrSerice);
        NSLog(@"arrSericeCOUNT:%d",arrSerice.count);
    }
    else
    {
        NSMutableArray *arrServicePointId=[self getServiceBrand:strBrand];
        for (int i=0; i<[arrServicePointId count]; i++) {
            NSMutableDictionary *dicItem=[arrServicePointId objectAtIndex:i];
            NSString *strId=[dicItem objectForKey:@"servicePointId"];
            NSString *select = [NSString stringWithFormat:@"SELECT * FROM %@ WHERE serverType='%@' and id='%@'",servicePointTable,strServiceType,strId];
            if(sqlite3_prepare_v2(database, [select UTF8String], -1, &statement, nil)!=SQLITE_OK)
            {
                sqlite3_close(database);
                NSAssert(0,@"Error querying:%s", err);
            }
            while (sqlite3_step(statement)==SQLITE_ROW)
            {
                
                NSString *strId=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 0)];
                NSString *strServerType=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 1)];
                NSString *strServerName=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 2)];
                NSString *strBrand=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 3)];
                NSString *strSupport=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 4)];
                NSString *strPhoneNo=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 5)];
                NSString *strAddress=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 6)];
                NSString *strPosition=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 7)];
                NSString *strPromotionstype=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 8)];
                NSString *strPromotions=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 9)];
                NSString *strPartner=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 10)];
                NSString *strExponent=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 11)];
                
                NSMutableDictionary *dictService=[[NSMutableDictionary alloc]init];
                [dictService setObject:strId forKey:@"id"];
                [dictService setObject:strServerType forKey:@"serverType"];
                [dictService setObject:strServerName forKey:@"name"];
                [dictService setObject:strBrand forKey:@"brand"];
                [dictService setObject:strSupport forKey:@"support"];
                [dictService setObject:strPhoneNo forKey:@"phoneNo"];
                [dictService setObject:strAddress forKey:@"address"];
                [dictService setObject:strPosition forKey:@"position"];
                [dictService setObject:strPromotionstype forKey:@"promotionstype"];
                [dictService setObject:strPromotions forKey:@"promotions"];
                [dictService setObject:strPartner forKey:@"partner"];
                [dictService setObject:strExponent forKey:@"exponent"];
                [arrSerice addObject:dictService];
                [dictService release];
            }
            NSLog(@"sqlite:arrSerice%@",arrSerice);
            NSLog(@"arrSericeCOUNT:%d",arrSerice.count);
        }

    }
   
 
    return arrSerice;
}
-(NSMutableArray *)getServiceBrand:(NSString *)strBrandCode
{
    NSString *serRelacBrandTable=@"SERVICE_RELACTION_BRAND";
    sqlite3_stmt *statement;
    if (strBrandCode.length==0) {
        strBrandCode=@"";
    }
    NSString *select = [NSString stringWithFormat:@"SELECT * FROM %@ WHERE brandCode='%@'",serRelacBrandTable,strBrandCode];
    NSMutableArray *arrSerice=[[NSMutableArray alloc]init];
    if(sqlite3_prepare_v2(database, [select UTF8String], -1, &statement, nil)!=SQLITE_OK)
    {
        sqlite3_close(database);
        NSAssert(0,@"Error querying:%s", err);
    }
    while (sqlite3_step(statement)==SQLITE_ROW)
    {
        
//        NSString *strId=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 0)];
        NSString *servicePointId=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 1)];
        NSString *brandCode=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 2)];
        
        NSMutableDictionary *dictService=[[NSMutableDictionary alloc]init];
        [dictService setObject:servicePointId forKey:@"servicePointId"];
        [dictService setObject:brandCode forKey:@"brandCode"];
        [arrSerice addObject:dictService];
        [dictService release];
    }
    NSLog(@"sqlite:arrSerice%@",arrSerice);
    NSLog(@"arrSericeCOUNT:%d",arrSerice.count);
    return arrSerice;
}

-(BOOL)insertCarList:(NSArray *)arrCarList withUserAccount:(NSString *)userAccount
{
    if (!arrCarList)
	{
		NSLog(@"empty arrCarList!");
		return 0;
		if (![arrCarList count])
		{
			NSLog(@"illegal arrCarList!");
			return 0;
		}
	}
    if ([arrCarList count]<=0) {
        return 0;
    }
    if (userAccount.length==0) {
        NSLog(@"用户名为空!");
        return 0;
    }
    NSLog(@"要插入的数据为:%@",arrCarList);
    for (int i=0; i<[arrCarList count]; i++) {
        NSMutableDictionary *dictItem=[arrCarList objectAtIndex:i];
        NSString *strCarID;
        if ([dictItem valueForKey:@"carID"]) {
            strCarID=[dictItem valueForKey:@"carID"];
        }else{
            strCarID=@"";
        }
        NSString *strCarIconUrl;
        if ([dictItem valueForKey:@"carIconUrl"]) {
            strCarIconUrl=[dictItem valueForKey:@"carIconUrl"];
        }else
        {
            strCarIconUrl=@"";
        }
        NSString *strCarName;
        if ([dictItem valueForKey:@"carName"]) {
            strCarName=[dictItem valueForKey:@"carName"];
        }else
        {
            strCarName=@"";
        }
        if ([self deleteCarList:strCarID withCarName:strCarName withUserAccount:userAccount]) {
            NSLog(@"删除数据成功!");
        }
        else
        {
            NSLog(@"删除数据失败!");
        }
    }
    for (int i=0; i<[arrCarList count]; i++) {
        NSMutableDictionary *dictItem=[arrCarList objectAtIndex:i];
        NSString *strCarID;
        if ([dictItem valueForKey:@"carID"]) {
            strCarID=[dictItem valueForKey:@"carID"];
        }else{
            strCarID=@"";
        }
        NSString *strCarIconUrl;
        if ([dictItem valueForKey:@"carIconUrl"]) {
            strCarIconUrl=[dictItem valueForKey:@"carIconUrl"];
        }else
        {
            strCarIconUrl=@"";
        }
        NSString *strCarName;
        if ([dictItem valueForKey:@"carName"]) {
            strCarName=[dictItem valueForKey:@"carName"];
        }else
        {
            strCarName=@"";
        }
        
        
        NSString *CARLISTTable=@"CARLIST";
        sqlite3_stmt *statement;

            NSString *replace = [NSString stringWithFormat:@"INSERT INTO %@ (carID,carIconUrl,carName,userAccount) VALUES (?,?,?,?)",CARLISTTable];
            if (sqlite3_prepare_v2(database, [replace UTF8String], -1, &statement, nil)== SQLITE_OK)
            {
                sqlite3_bind_text(statement,1,[strCarID UTF8String],-1,NULL);
                sqlite3_bind_text(statement,2,[strCarIconUrl UTF8String],-1,NULL);
                sqlite3_bind_text(statement,3,[strCarName UTF8String],-1,NULL);
                sqlite3_bind_text(statement,4,[userAccount UTF8String],-1,NULL);
                
            }
            NSLog(@"%d",sqlite3_step(statement));
            
    }
    return 1;
}

-(BOOL)deleteCarList:(NSString *)strCarID withCarName:(NSString *)strCarName withUserAccount:(NSString *)userAccount
{
    NSString *tableDelete=@"CARLIST";
    NSString *sqlDeleteAAA=[NSString stringWithFormat:@"delete from %@ where carID='%@' and userAccount='%@'",tableDelete,strCarID,userAccount];
	sqlite3_stmt *statement;
	
	int linkCode = sqlite3_prepare_v2(database, [sqlDeleteAAA UTF8String], [sqlDeleteAAA length], &statement, NULL);
	if (linkCode != SQLITE_OK) {
		return NO;
	}
	linkCode = sqlite3_step(statement);
	sqlite3_finalize(statement);
	if (linkCode != SQLITE_DONE) {
		return NO;
	}
	return YES;
}

-(NSMutableArray *)getCarList:(NSString *)userAccount
{
    NSString *CARLISTTable=@"CARLIST";
    if (userAccount.length==0) {
        userAccount=@"";
    }
    sqlite3_stmt *statement;
    NSString *select = [NSString stringWithFormat:@"SELECT * FROM %@ where userAccount='%@'",CARLISTTable,userAccount];
    NSMutableArray *arrSerice=[[NSMutableArray alloc]init];
    if(sqlite3_prepare_v2(database, [select UTF8String], -1, &statement, nil)!=SQLITE_OK)
    {
        sqlite3_close(database);
        NSAssert(0,@"Error querying:%s", err);
    }
    while (sqlite3_step(statement)==SQLITE_ROW)
    {
        
        NSString *strCarID=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 1)];
        NSString *strCarIconUrl=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 2)];
        NSString *strCarName=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 3)];
        
        NSMutableDictionary *dictService=[[NSMutableDictionary alloc]init];
        [dictService setObject:strCarID forKey:@"carID"];
        [dictService setObject:strCarIconUrl forKey:@"carIconUrl"];
        [dictService setObject:strCarName forKey:@"carName"];
        [arrSerice addObject:dictService];
        [dictService release];
    }
    NSLog(@"sqlite:count-%d",[arrSerice count]);
    NSLog(@"sqlite:arrSerice%@",arrSerice);
    return arrSerice;
}

-(BOOL)insertCarDetail:(NSMutableDictionary *)dictCarDetail withCarID:(NSString *)strCarID withUserAccouont:(NSString *)userAccount;
{
    if (!dictCarDetail)
	{
		NSLog(@"empty dictCarDetail!");
		return 0;
		if (![dictCarDetail count])
		{
			NSLog(@"illegal dictCarDetail!");
			return 0;
		}
	}
    if ([dictCarDetail count]<=0) {
        return 0;
    }
    if (userAccount.length==0) {
        NSLog(@"用户名为空!");
        return 0;
    }
    NSLog(@"要插入的数据为:%@",dictCarDetail);

    if ([self deleteCarDetail:strCarID withUserAccount:userAccount]) {
            NSLog(@"删除数据成功!");
    }else
    {
            NSLog(@"删除数据失败!");
    }
    
        NSString *strManufacturers;
        if ([dictCarDetail valueForKey:@"manufacturers"]) {
            strManufacturers=[dictCarDetail valueForKey:@"manufacturers"];
        }else
        {
            strManufacturers=@"";
        }
        NSString *strManufacturersName;
        if ([dictCarDetail valueForKey:@"manufacturersName"]) {
            strManufacturersName=[dictCarDetail valueForKey:@"manufacturersName"];
        }else
        {
            strManufacturersName=@"";
        }
    NSString *strBrand;
    if ([dictCarDetail valueForKey:@"brand"]) {
        strBrand=[dictCarDetail valueForKey:@"brand"];
    }else
    {
        strBrand=@"";
    }
    NSString *strBrandName;
    if ([dictCarDetail valueForKey:@"brandName"]) {
        strBrandName=[dictCarDetail valueForKey:@"brandName"];
    }else
    {
        strBrandName=@"";
    }
    NSString *strType;
    if ([dictCarDetail valueForKey:@"type"]) {
        strType=[dictCarDetail valueForKey:@"type"];
    }else
    {
        strType=@"";
    }
    NSString *strTypeName;
    if ([dictCarDetail valueForKey:@"typeName"]) {
        strTypeName=[dictCarDetail valueForKey:@"typeName"];
    }else
    {
        strTypeName=@"";
    }
    NSString *strLicense;
    if ([dictCarDetail valueForKey:@"license"]) {
        strLicense=[dictCarDetail valueForKey:@"license"];
    }else
    {
        strLicense=@"";
    }
    NSString *strName;
    if ([dictCarDetail valueForKey:@"name"]) {
        strName=[dictCarDetail valueForKey:@"name"];
    }else
    {
        strName=@"";
    }
    NSString *strPolicyHolder;
    if ([dictCarDetail valueForKey:@"policyHolder"]) {
        strPolicyHolder=[dictCarDetail valueForKey:@"policyHolder"];
    }else
    {
        strPolicyHolder=@"";
    }
    NSString *strIdType;
    if ([dictCarDetail valueForKey:@"idType"]) {
        strIdType=[dictCarDetail valueForKey:@"idType"];
    }else
    {
        strIdType=@"";
    }
    NSString *strIDNum;
    if ([dictCarDetail valueForKey:@"iDNum"]) {
        strIDNum=[dictCarDetail valueForKey:@"iDNum"];
    }else
    {
        strIDNum=@"";
    }
    NSString *strFirstDate;
    if ([dictCarDetail valueForKey:@"firstDate"]) {
        strFirstDate=[dictCarDetail valueForKey:@"firstDate"];
    }else
    {
        strFirstDate=@"";
    }
        
        
        NSString *CARDETAILTable=@"CARDETAIL";
        sqlite3_stmt *statement;
        
        NSString *replace = [NSString stringWithFormat:@"INSERT INTO %@ (carID,manufacturers,manufacturersName,brand,brandName,type,typeName,license,name,policyHolder,idType,iDNum,firstDate,userAccount) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)",CARDETAILTable];
        if (sqlite3_prepare_v2(database, [replace UTF8String], -1, &statement, nil)== SQLITE_OK)
        {
            sqlite3_bind_text(statement,1,[strCarID UTF8String],-1,NULL);
            sqlite3_bind_text(statement,2,[strManufacturers UTF8String],-1,NULL);
            sqlite3_bind_text(statement,3,[strManufacturersName UTF8String],-1,NULL);
            sqlite3_bind_text(statement,4,[strBrand UTF8String],-1,NULL);
            sqlite3_bind_text(statement,5,[strBrandName UTF8String],-1,NULL);
            sqlite3_bind_text(statement,6,[strType UTF8String],-1,NULL);
            sqlite3_bind_text(statement,7,[strTypeName UTF8String],-1,NULL);
            sqlite3_bind_text(statement,8,[strLicense UTF8String],-1,NULL);
            sqlite3_bind_text(statement,9,[strName UTF8String],-1,NULL);
            sqlite3_bind_text(statement,10,[strPolicyHolder UTF8String],-1,NULL);
            sqlite3_bind_text(statement,11,[strIdType UTF8String],-1,NULL);
            sqlite3_bind_text(statement,12,[strIDNum UTF8String],-1,NULL);
            sqlite3_bind_text(statement,13,[strFirstDate UTF8String],-1,NULL);
            sqlite3_bind_text(statement,14,[userAccount UTF8String],-1,NULL);
            
        }
        NSLog(@"%d",sqlite3_step(statement));
        
    return 1;
}

-(BOOL)deleteCarDetail:(NSString *)strCarID withUserAccount:(NSString *)userAccount
{
    NSString *tableDelete=@"CARDETAIL";
    NSString *sqlDelete=[NSString stringWithFormat:@"delete from %@ where carID='%@' and userAccouont='%@'",tableDelete,strCarID,userAccount];
	sqlite3_stmt *statement;
	
	int linkCode = sqlite3_prepare_v2(database, [sqlDelete UTF8String], [sqlDelete length], &statement, NULL);
	if (linkCode != SQLITE_OK) {
		return NO;
	}
	linkCode = sqlite3_step(statement);
	sqlite3_finalize(statement);
	if (linkCode != SQLITE_DONE) {
		return NO;
	}
	return YES;
}

-(NSMutableDictionary *)getCarDetail:(NSString *)strCarID withUserAccount:(NSString *)userAccount
{
    NSString *CARLISTTable=@"CARDETAIL";
    sqlite3_stmt *statement;
    NSString *select = [NSString stringWithFormat:@"SELECT * FROM %@ WHERE carID='%@' and userAccount='%@'",CARLISTTable,strCarID,userAccount];
    if(sqlite3_prepare_v2(database, [select UTF8String], -1, &statement, nil)!=SQLITE_OK)
    {
        sqlite3_close(database);
        NSAssert(0,@"Error querying:%s", err);
    }
    NSMutableDictionary *dictService=[[NSMutableDictionary alloc]init];
    while (sqlite3_step(statement)==SQLITE_ROW)
    {
        
        NSString *strCarID=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 1)];
        NSString *strManufacturers=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 2)];
        NSString *strManufacturersName=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 3)];
        NSString *strBrand=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 4)];
        NSString *strBrandName=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 5)];
        NSString *strType=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 6)];
        NSString *strTypeName=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 7)];
        NSString *strLicense=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 8)];
        NSString *strName=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 9)];
        NSString *strPolicyHolder=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 10)];
        NSString *strIdType=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 11)];
        NSString *strIDNum=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 12)];
        NSString *strFirstDate=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 13)];
        
        
        [dictService setObject:strCarID forKey:@"carID"];
        [dictService setObject:strManufacturers forKey:@"manufacturers"];
        [dictService setObject:strManufacturersName forKey:@"manufacturersName"];
        [dictService setObject:strBrand forKey:@"brand"];
        [dictService setObject:strBrandName forKey:@"brandName"];
        [dictService setObject:strType forKey:@"type"];
        [dictService setObject:strTypeName forKey:@"typeName"];
        [dictService setObject:strLicense forKey:@"license"];
        [dictService setObject:strName forKey:@"name"];
        [dictService setObject:strPolicyHolder forKey:@"policyHolder"];
        [dictService setObject:strIdType forKey:@"idType"];
        [dictService setObject:strIDNum forKey:@"iDNum"];
        [dictService setObject:strFirstDate forKey:@"firstDate"];
    }
    NSLog(@"sqlite:count-%d",[dictService count]);
    NSLog(@"sqlite:dictService%@",dictService);
    return dictService;
}

-(BOOL)insertPolicyData:(NSMutableArray *)arrInsPolicyList withUserAccount:(NSString *)userAccount withTag:(NSString *)strTag withPlateNo:(NSString *)strPlateNo withCertificateno:(NSString *)strCertificateno
{
    if (!arrInsPolicyList)
	{
		NSLog(@"empty arrInsPolicyList!");
		return 0;
		if (![arrInsPolicyList count])
		{
			NSLog(@"illegal arrCarList!");
			return 0;
		}
	}
    if ([arrInsPolicyList count]<=0) {
        return 0;
    }
    if (userAccount.length==0) {
        NSLog(@"用户名为空!");
        return 0;
    }
    NSLog(@"要插入的数据为:%@",arrInsPolicyList);
    for (int i=0; i<[arrInsPolicyList count]; i++) {
        NSMutableDictionary *dictItem=[arrInsPolicyList objectAtIndex:i];
        NSString *strPolicyNo;
        if ([dictItem valueForKey:@"policyno"]) {
            strPolicyNo=[dictItem valueForKey:@"policyno"];
        }else{
            strPolicyNo=@"";
        }
        if ([self deletePolicyData:strPolicyNo withUserAccount:userAccount]) {
            NSLog(@"删除数据成功!");
        }
        else
        {
            NSLog(@"删除数据失败!");
        }
    }
    for (int i=0; i<[arrInsPolicyList count]; i++) {
        NSMutableDictionary *dictItem=[arrInsPolicyList objectAtIndex:i];
        NSString *strPolicyNo;
        if ([dictItem valueForKey:@"policyno"]) {
            strPolicyNo=[dictItem valueForKey:@"policyno"];
        }else{
            strPolicyNo=@"";
        }
        NSString *strProductname;
        if ([dictItem valueForKey:@"productname"]) {
            strProductname=[dictItem valueForKey:@"productname"];
        }else
        {
            strProductname=@"";
        }
        NSString *strStartdate;
        if ([dictItem valueForKey:@"startdate"]) {
            strStartdate=[dictItem valueForKey:@"startdate"];
        }else
        {
            strStartdate=@"";
        }
        NSString *strEnddate;
        if ([dictItem valueForKey:@"enddate"]) {
            strEnddate=[dictItem valueForKey:@"enddate"];
        }else
        {
            strEnddate=@"";
        }
        
        
        NSString *POLICYTable=@"POLICY_DATA";
        sqlite3_stmt *statement;
        
        NSString *replace = [NSString stringWithFormat:@"INSERT INTO %@ (policyno,productname,startdate,enddate,userAccount,tag,PlateNo,certificateno) VALUES (?,?,?,?,?,?,?,?)",POLICYTable];
        if (sqlite3_prepare_v2(database, [replace UTF8String], -1, &statement, nil)== SQLITE_OK)
        {
            sqlite3_bind_text(statement,1,[strPolicyNo UTF8String],-1,NULL);
            sqlite3_bind_text(statement,2,[strProductname UTF8String],-1,NULL);
            sqlite3_bind_text(statement,3,[strStartdate UTF8String],-1,NULL);
            sqlite3_bind_text(statement,4,[strEnddate UTF8String],-1,NULL);
            sqlite3_bind_text(statement,5,[userAccount UTF8String],-1,NULL);
            sqlite3_bind_text(statement,6,[strTag UTF8String],-1,NULL);
            sqlite3_bind_text(statement,7,[strPlateNo UTF8String],-1,NULL);
            sqlite3_bind_text(statement,8,[strCertificateno UTF8String],-1,NULL);
            
        }
        NSLog(@"%d",sqlite3_step(statement));
        
    }
    return 1;

}
-(BOOL)deletePolicyData:(NSString *)strPolicyNo withUserAccount:(NSString *)userAccount
{
    NSString *tableDelete=@"POLICY_DATA";
    NSString *sqlDelete=[NSString stringWithFormat:@"delete from %@ where policyno='%@' and userAccount='%@'",tableDelete,strPolicyNo,userAccount];
	sqlite3_stmt *statement;
	
	int linkCode = sqlite3_prepare_v2(database, [sqlDelete UTF8String], [sqlDelete length], &statement, NULL);
	if (linkCode != SQLITE_OK) {
		return NO;
	}
	linkCode = sqlite3_step(statement);
	sqlite3_finalize(statement);
	if (linkCode != SQLITE_DONE) {
		return NO;
	}
	return YES;
}
-(NSMutableArray *)getPolictData:(NSString *)userAccount withTag:(NSString *)strTag  withPlateNo:(NSString *)strPlateNo
{
    //strTag="1"表示查的是现在的保单,strTag=@"0"表示查的是历史保单
    NSString *POLICYTable=@"POLICY_DATA";
    if (userAccount.length==0) {
        userAccount=@"";
    }
    if (strTag.length==0) {
        strTag=@"";
    }
    sqlite3_stmt *statement;
    NSString *select = [NSString stringWithFormat:@"SELECT * FROM %@ where userAccount='%@' and tag='%@' and PlateNo='%@'",POLICYTable,userAccount,strTag,strPlateNo];
    NSMutableArray *arrSerice=[[NSMutableArray alloc]init];
    if(sqlite3_prepare_v2(database, [select UTF8String], -1, &statement, nil)!=SQLITE_OK)
    {
        sqlite3_close(database);
        NSAssert(0,@"Error querying:%s", err);
    }
    while (sqlite3_step(statement)==SQLITE_ROW)
    {
        
        NSString *strPolicyNo=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 0)];
        NSString *strProductname=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 1)];
        NSString *strStartdate=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 2)];
        NSString *strEnddate=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 3)];
        
        NSMutableDictionary *dictService=[[NSMutableDictionary alloc]init];
        [dictService setObject:strPolicyNo forKey:@"policyno"];
        [dictService setObject:strProductname forKey:@"productname"];
        [dictService setObject:strStartdate forKey:@"startdate"];
        [dictService setObject:strEnddate forKey:@"enddate"];
        [arrSerice addObject:dictService];
        [dictService release];
    }
    NSLog(@"sqlite:count-%d",[arrSerice count]);
    NSLog(@"sqlite:arrSerice%@",arrSerice);
    return arrSerice;
}

-(BOOL)insertPolicyKindData:(NSMutableArray *)arrInsPolicyKindList withUserAccount:(NSString *)userAccount withPolicyNo:(NSString *)strPolicyNo
{
    if (!arrInsPolicyKindList)
	{
		NSLog(@"empty arrInsPolicyKindList!");
		return 0;
		if (![arrInsPolicyKindList count])
		{
			NSLog(@"illegal arrInsPolicyKindList!");
			return 0;
		}
	}
    if ([arrInsPolicyKindList count]<=0) {
        return 0;
    }
    if (userAccount.length==0) {
        NSLog(@"用户名为空!");
        return 0;
    }
    NSLog(@"要插入的数据为:%@",arrInsPolicyKindList);
    for (int i=0; i<[arrInsPolicyKindList count]; i++) {
        NSMutableDictionary *dictItem=[arrInsPolicyKindList objectAtIndex:i];
        NSString *strPolicyNo;
        if ([dictItem valueForKey:@"policyno"]) {
            strPolicyNo=[dictItem valueForKey:@"policyno"];
        }else{
            strPolicyNo=@"";
        }
        NSString *strSubCoverage;
        if ([dictItem valueForKey:@"subcoverage"]) {
            strSubCoverage=[dictItem valueForKey:@"subcoverage"];
        }else
        {
            strSubCoverage=@"";
        }
        if ([self deletePolicyKindData:strPolicyNo withUserAccount:userAccount withSubCoverage:strSubCoverage]) {
            NSLog(@"删除数据成功!");
        }
        else
        {
            NSLog(@"删除数据失败!");
        }
    }
    for (int i=0; i<[arrInsPolicyKindList count]; i++) {
        NSMutableDictionary *dictItem=[arrInsPolicyKindList objectAtIndex:i];
        NSString *strPolicyNo;
        if ([dictItem valueForKey:@"policyno"]) {
            strPolicyNo=[dictItem valueForKey:@"policyno"];
        }else{
            strPolicyNo=@"";
        }
        NSString *strSubCoverage;
        if ([dictItem valueForKey:@"subcoverage"]) {
            strSubCoverage=[dictItem valueForKey:@"subcoverage"];
        }else
        {
            strSubCoverage=@"";
        }
        NSString *strSubcoveragename;
        if ([dictItem valueForKey:@"subcoveragename"]) {
            strSubcoveragename=[dictItem valueForKey:@"subcoveragename"];
        }else
        {
            strSubcoveragename=@"";
        }
        NSString *strInsuredamount;
        if ([dictItem valueForKey:@"insuredamount"]) {
            strInsuredamount=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"insuredamount"]];
        }else
        {
            strInsuredamount=@"";
        }
        NSString *strGrosspremium;
        if ([dictItem valueForKey:@"grosspremium"]) {
            strGrosspremium=[[NSString alloc]initWithFormat:@"%@",[dictItem valueForKey:@"grosspremium"]];
        }else
        {
            strGrosspremium=@"";
        }
        
        
        NSString *POLICYTable=@"POLICY_KIND_DATA";
        sqlite3_stmt *statement;
        
        NSString *replace = [NSString stringWithFormat:@"INSERT INTO %@ (policyno,subcoveragename,insuredamount,grosspremium,subcoverage,userAccount) VALUES (?,?,?,?,?,?)",POLICYTable];
        if (sqlite3_prepare_v2(database, [replace UTF8String], -1, &statement, nil)== SQLITE_OK)
        {
            sqlite3_bind_text(statement,1,[strPolicyNo UTF8String],-1,NULL);
            sqlite3_bind_text(statement,2,[strSubcoveragename UTF8String],-1,NULL);
            sqlite3_bind_text(statement,3,[strInsuredamount UTF8String],-1,NULL);
            sqlite3_bind_text(statement,4,[strGrosspremium UTF8String],-1,NULL);
            sqlite3_bind_text(statement,5,[strSubCoverage UTF8String],-1,NULL);
            sqlite3_bind_text(statement,6,[userAccount UTF8String],-1,NULL);
            
        }
        NSLog(@"%d",sqlite3_step(statement));
        
    }
    return 1;

}

-(BOOL)deletePolicyKindData:(NSString *)strPolicyNo withUserAccount:(NSString *)userAccount withSubCoverage:(NSString *)strSubCoverage
{
    NSString *tableDelete=@"POLICY_KIND_DATA";
    NSString *sqlDeleteAAA=[NSString stringWithFormat:@"delete from %@ where policyno='%@' and userAccount='%@' and subcoverage='%@'",tableDelete,strPolicyNo,userAccount,strSubCoverage];
	sqlite3_stmt *statement;
	
	int linkCode = sqlite3_prepare_v2(database, [sqlDeleteAAA UTF8String], [sqlDeleteAAA length], &statement, NULL);
	if (linkCode != SQLITE_OK) {
		return NO;
	}
	linkCode = sqlite3_step(statement);
	sqlite3_finalize(statement);
	if (linkCode != SQLITE_DONE) {
		return NO;
	}
	return YES;
}
-(NSMutableArray *)getPolictKindData:(NSString *)userAccount withPolicyNo:(NSString *)strPolicyNo
{
    NSString *POLICYTable=@"POLICY_KIND_DATA";
    if (userAccount.length==0) {
        userAccount=@"";
    }
    if (strPolicyNo.length==0) {
        strPolicyNo=@"";
    }
    sqlite3_stmt *statement;
    NSString *select = [NSString stringWithFormat:@"SELECT * FROM %@ where userAccount='%@' and policyno='%@'",POLICYTable,userAccount,strPolicyNo];
    NSMutableArray *arrSerice=[[NSMutableArray alloc]init];
    if(sqlite3_prepare_v2(database, [select UTF8String], -1, &statement, nil)!=SQLITE_OK)
    {
        sqlite3_close(database);
        NSAssert(0,@"Error querying:%s", err);
    }
    while (sqlite3_step(statement)==SQLITE_ROW)
    {
        
        NSString *strPolicyNo=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 0)];
        NSString *strSubcoveragename=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 1)];
        NSString *strInsuredamount=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 2)];
        NSString *strGrosspremium=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 3)];
        NSString *strSubcoverage=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 4)];
        
        NSMutableDictionary *dictService=[[NSMutableDictionary alloc]init];
        [dictService setObject:strPolicyNo forKey:@"policyno"];
        [dictService setObject:strSubcoveragename forKey:@"subcoveragename"];
        [dictService setObject:strInsuredamount forKey:@"insuredamount"];
        [dictService setObject:strGrosspremium forKey:@"grosspremium"];
        [dictService setObject:strSubcoverage forKey:@"subcoverage"];
        [arrSerice addObject:dictService];
        [dictService release];
    }
    NSLog(@"sqlite:count-%d",[arrSerice count]);
    NSLog(@"sqlite:arrSerice%@",arrSerice);
    return arrSerice;
}

-(BOOL)insertPolicyMainData:(NSMutableDictionary *)dictPolicyMainData withPolicyNo:(NSString *)strPolicyNo withUserAccouont:(NSString *)userAccount
{
    if (!dictPolicyMainData)
	{
		NSLog(@"empty dictPolicyMainData!");
		return 0;
		if (![dictPolicyMainData count])
		{
			NSLog(@"illegal dictPolicyMainData!");
			return 0;
		}
	}
    if ([dictPolicyMainData count]<=0) {
        return 0;
    }
    if (userAccount.length==0) {
        NSLog(@"用户名为空!");
        return 0;
    }
    NSLog(@"要插入的数据为:%@",dictPolicyMainData);
    
    if ([self deletePolicyMainData:strPolicyNo withUserAccount:userAccount]) {
        NSLog(@"删除数据成功!");
    }else
    {
        NSLog(@"删除数据失败!");
    }
    
    NSString *strPolicyno;
    if ([dictPolicyMainData valueForKey:@"policyno"]) {
        strPolicyno=[dictPolicyMainData valueForKey:@"policyno"];
    }else
    {
        strPolicyno=@"";
    }
    NSString *strApplyname;
    if ([dictPolicyMainData valueForKey:@"applyname"]) {
        strApplyname=[dictPolicyMainData valueForKey:@"applyname"];
    }else
    {
        strApplyname=@"";
    }
    NSString *strEnddate;
    if ([dictPolicyMainData valueForKey:@"enddate"]) {
        strEnddate=[dictPolicyMainData valueForKey:@"enddate"];
    }else
    {
        strEnddate=@"";
    }
    NSString *strInsuredname;
    if ([dictPolicyMainData valueForKey:@"insuredname"]) {
        strInsuredname=[dictPolicyMainData valueForKey:@"insuredname"];
    }else
    {
        strInsuredname=@"";
    }
    NSString *strProductname;
    if ([dictPolicyMainData valueForKey:@"productname"]) {
        strProductname=[dictPolicyMainData valueForKey:@"productname"];
    }else
    {
        strProductname=@"";
    }
    NSString *strStartdate;
    if ([dictPolicyMainData valueForKey:@"startdate"]) {
        strStartdate=[dictPolicyMainData valueForKey:@"startdate"];
    }else
    {
        strStartdate=@"";
    }
    NSString *strStatusname;
    if ([dictPolicyMainData valueForKey:@"statusname"]) {
        strStatusname=[dictPolicyMainData valueForKey:@"statusname"];
    }else
    {
        strStatusname=@"";
    }
    
    
    NSString *POLICY_MAIN_DATA_Table=@"POLICY_MAIN_DATA";
    sqlite3_stmt *statement;
    
    NSString *replace = [NSString stringWithFormat:@"INSERT INTO %@ (policyno,insuredname,applyname,productname,startdate,enddate,statusname,userAccount) VALUES (?,?,?,?,?,?,?,?)",POLICY_MAIN_DATA_Table];
    if (sqlite3_prepare_v2(database, [replace UTF8String], -1, &statement, nil)== SQLITE_OK)
    {
        sqlite3_bind_text(statement,1,[strPolicyNo UTF8String],-1,NULL);
        sqlite3_bind_text(statement,2,[strInsuredname UTF8String],-1,NULL);
        sqlite3_bind_text(statement,3,[strApplyname UTF8String],-1,NULL);
        sqlite3_bind_text(statement,4,[strProductname UTF8String],-1,NULL);
        sqlite3_bind_text(statement,5,[strStartdate UTF8String],-1,NULL);
        sqlite3_bind_text(statement,6,[strEnddate UTF8String],-1,NULL);
        sqlite3_bind_text(statement,7,[strStatusname UTF8String],-1,NULL);
        sqlite3_bind_text(statement,8,[userAccount UTF8String],-1,NULL);
        
    }
    NSLog(@"%d",sqlite3_step(statement));
    
    return 1;
}

-(BOOL)deletePolicyMainData:(NSString *)strPolicyNo withUserAccount:(NSString *)userAccount
{
    NSString *tableDelete=@"POLICY_MAIN_DATA";
    NSString *sqlDelete=[NSString stringWithFormat:@"delete from %@ where policyno='%@' and userAccount='%@'",tableDelete,strPolicyNo,userAccount];
	sqlite3_stmt *statement;
	
	int linkCode = sqlite3_prepare_v2(database, [sqlDelete UTF8String], [sqlDelete length], &statement, NULL);
	if (linkCode != SQLITE_OK) {
		return NO;
	}
	linkCode = sqlite3_step(statement);
	sqlite3_finalize(statement);
	if (linkCode != SQLITE_DONE) {
		return NO;
	}
	return YES;
}

-(NSMutableDictionary *)getPolicyMainData:(NSString *)strPolicyNo withUserAccount:(NSString *)userAccount
{
    NSString *POLICY_MAIN_DATA_Table=@"POLICY_MAIN_DATA";
    sqlite3_stmt *statement;
    NSString *select = [NSString stringWithFormat:@"SELECT * FROM %@ WHERE policyno='%@' and userAccount='%@'",POLICY_MAIN_DATA_Table,strPolicyNo,userAccount];
    if(sqlite3_prepare_v2(database, [select UTF8String], -1, &statement, nil)!=SQLITE_OK)
    {
        sqlite3_close(database);
        NSAssert(0,@"Error querying:%s", err);
    }
    NSMutableDictionary *dictService=[[NSMutableDictionary alloc]init];
    while (sqlite3_step(statement)==SQLITE_ROW)
    {
        NSString *strPolicynoA=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 0)];
        NSString *strInsuredname=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 1)];
        NSString *strApplyname=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 2)];
        NSString *strProductname=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 4)];
        NSString *strStartdate=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 5)];
        NSString *strEnddate=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 6)];
        NSString *strStatusname=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 7)];
        
        
        [dictService setObject:strPolicynoA forKey:@"policyno"];
        [dictService setObject:strInsuredname forKey:@"insuredname"];
        [dictService setObject:strApplyname forKey:@"applyname"];
        //[dictService setObject:strProductname forKey:@"companyName"];
        [dictService setObject:strProductname forKey:@"productname"];
        [dictService setObject:strStartdate forKey:@"startdate"];
        [dictService setObject:strEnddate forKey:@"enddate"];
        [dictService setObject:strStatusname forKey:@"statusname"];
    }
    NSLog(@"sqlite:count-%d",[dictService count]);
    NSLog(@"sqlite:dictService%@",dictService);
    return dictService;
}

-(BOOL)insertPolicyCarData:(NSMutableDictionary *)dictPolicyCarData withPolicyNo:(NSString *)strPolicyNo withUserAccouont:(NSString *)userAccount
{
    if (!dictPolicyCarData)
	{
		NSLog(@"empty dictPolicyCarData!");
		return 0;
		if (![dictPolicyCarData count])
		{
			NSLog(@"illegal dictPolicyCarData!");
			return 0;
		}
	}
    if ([dictPolicyCarData count]<=0) {
        return 0;
    }
    if (userAccount.length==0) {
        NSLog(@"用户名为空!");
        return 0;
    }
    NSLog(@"要插入的数据为:%@",dictPolicyCarData);
    
    if ([self deletePolicyCarData:strPolicyNo withUserAccount:userAccount]) {
        NSLog(@"删除数据成功!");
    }else
    {
        NSLog(@"删除数据失败!");
    }
    
    NSString *strPolicyno;
    if ([dictPolicyCarData valueForKey:@"policyno"]) {
        strPolicyno=[dictPolicyCarData valueForKey:@"policyno"];
    }else
    {
        strPolicyno=@"";
    }
    NSString *strPlateno;
    if ([dictPolicyCarData valueForKey:@"plateno"]) {
        strPlateno=[dictPolicyCarData valueForKey:@"plateno"];
    }else
    {
        strPlateno=@"";
    }
    NSString *strProductcode;
    if ([dictPolicyCarData valueForKey:@"productcode"]) {
        strProductcode=[dictPolicyCarData valueForKey:@"productcode"];
    }else
    {
        strProductcode=@"";
    }
    NSString *strSeatnumber;
    if ([dictPolicyCarData valueForKey:@"seatnumber"]) {
        strSeatnumber=[dictPolicyCarData valueForKey:@"seatnumber"];
    }else
    {
        strSeatnumber=@"";
    }
    NSString *strSerialno;
    if ([dictPolicyCarData valueForKey:@"serialno"]) {
        strSerialno=[dictPolicyCarData valueForKey:@"serialno"];
    }else
    {
        strSerialno=@"";
    }
    NSString *strVehicletype;
    if ([dictPolicyCarData valueForKey:@"vehicletype"]) {
        strVehicletype=[dictPolicyCarData valueForKey:@"vehicletype"];
    }else
    {
        strVehicletype=@"";
    }
    NSString *strVehicletypename;
    if ([dictPolicyCarData valueForKey:@"vehicletypename"]) {
        strVehicletypename=[dictPolicyCarData valueForKey:@"vehicletypename"];
    }else
    {
        strVehicletypename=@"";
    }
    NSString *strVehiclevin;
    if ([dictPolicyCarData valueForKey:@"vehiclevin"]) {
        strVehiclevin=[dictPolicyCarData valueForKey:@"vehiclevin"];
    }else
    {
        strVehiclevin=@"";
    }
    NSString *strWeight;
    if ([dictPolicyCarData valueForKey:@"weight"]) {
        strWeight=[dictPolicyCarData valueForKey:@"weight"];
    }else
    {
        strWeight=@"";
    }
    
    NSString *POLICY_CAR_DATA_Table=@"POLICY_CAR_DATA";
    sqlite3_stmt *statement;
    
    NSString *replace = [NSString stringWithFormat:@"INSERT INTO %@ (policyno,plateno,productcode,seatnumber,serialno,vehicletype,vehicletypename,vehiclevin,weight,userAccount) VALUES (?,?,?,?,?,?,?,?,?,?)",POLICY_CAR_DATA_Table];
    if (sqlite3_prepare_v2(database, [replace UTF8String], -1, &statement, nil)== SQLITE_OK)
    {
        sqlite3_bind_text(statement,1,[strPolicyNo UTF8String],-1,NULL);
        sqlite3_bind_text(statement,2,[strPlateno UTF8String],-1,NULL);
        sqlite3_bind_text(statement,3,[strProductcode UTF8String],-1,NULL);
        sqlite3_bind_text(statement,4,[strSeatnumber UTF8String],-1,NULL);
        sqlite3_bind_text(statement,5,[strSerialno UTF8String],-1,NULL);
        sqlite3_bind_text(statement,6,[strVehicletype UTF8String],-1,NULL);
        sqlite3_bind_text(statement,7,[strVehicletypename UTF8String],-1,NULL);
        sqlite3_bind_text(statement,8,[strVehiclevin UTF8String],-1,NULL);
        sqlite3_bind_text(statement,9,[strWeight UTF8String],-1,NULL);
        sqlite3_bind_text(statement,10,[userAccount UTF8String],-1,NULL);
        
    }
    NSLog(@"%d",sqlite3_step(statement));
    
    return 1;

}
-(BOOL)deletePolicyCarData:(NSString *)strPolicyNo withUserAccount:(NSString *)userAccount
{
    NSString *tableDelete=@"POLICY_CAR_DATA";
    NSString *sqlDelete=[NSString stringWithFormat:@"delete from %@ where policyno='%@' and userAccouont='%@'",tableDelete,strPolicyNo,userAccount];
	sqlite3_stmt *statement;
	
	int linkCode = sqlite3_prepare_v2(database, [sqlDelete UTF8String], [sqlDelete length], &statement, NULL);
	if (linkCode != SQLITE_OK) {
		return NO;
	}
	linkCode = sqlite3_step(statement);
	sqlite3_finalize(statement);
	if (linkCode != SQLITE_DONE) {
		return NO;
	}
	return YES;
}

-(NSMutableArray *)getPolicyCarData:(NSString *)strPolicyNo withUserAccount:(NSString *)userAccount
{
    NSString *POLICY_CAR_DATA_Table=@"POLICY_CAR_DATA";
    if (userAccount.length==0) {
        userAccount=@"";
    }
    if (strPolicyNo.length==0) {
        strPolicyNo=@"";
    }
    sqlite3_stmt *statement;
    NSString *select = [NSString stringWithFormat:@"SELECT * FROM %@ where userAccount='%@' and policyno='%@'",POLICY_CAR_DATA_Table,userAccount,strPolicyNo];
    NSMutableArray *arrSerice=[[NSMutableArray alloc]init];
    if(sqlite3_prepare_v2(database, [select UTF8String], -1, &statement, nil)!=SQLITE_OK)
    {
        sqlite3_close(database);
        NSAssert(0,@"Error querying:%s", err);
    }
    while (sqlite3_step(statement)==SQLITE_ROW)
    {
        
        NSString *strPolicyNo=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 0)];
        NSString *strPlateno=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 1)];
        NSString *strProductcode=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 2)];
        NSString *strSeatnumber=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 3)];
        NSString *strSerialno=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 4)];
        NSString *strVehicletype=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 5)];
        NSString *strVehicletypename=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 6)];
        NSString *strVehiclevin=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 7)];
        NSString *strWeight=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 8)];
        NSString *strUserAccount=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 9)];
        
        NSMutableDictionary *dictService=[[NSMutableDictionary alloc]init];
        [dictService setObject:strPolicyNo forKey:@"policyno"];
        [dictService setObject:strPlateno forKey:@"plateno"];
        [dictService setObject:strProductcode forKey:@"productcode"];
        [dictService setObject:strSeatnumber forKey:@"seatnumber"];
        [dictService setObject:strSerialno forKey:@"serialno"];
        [dictService setObject:strVehicletype forKey:@"vehicletype"];
        [dictService setObject:strVehicletypename forKey:@"vehicletypename"];
        [dictService setObject:strVehiclevin forKey:@"vehiclevin"];
        [dictService setObject:strWeight forKey:@"weight"];
        [dictService setObject:strUserAccount forKey:@"userAccount"];
        [arrSerice addObject:dictService];
        [dictService release];
    }
    NSLog(@"sqlite:count-%d",[arrSerice count]);
    NSLog(@"sqlite:arrSerice%@",arrSerice);
    return arrSerice;
}

-(BOOL)insertServiceNoticeData:(NSMutableArray *)arrServiceNoticeList withUserAccount:(NSString *)userAccount
{
    if (!arrServiceNoticeList)
	{
		NSLog(@"empty arrServiceNoticeList!");
		return 0;
		if (![arrServiceNoticeList count])
		{
			NSLog(@"illegal arrServiceNoticeList!");
			return 0;
		}
	}
    if ([arrServiceNoticeList count]<=0) {
        return 0;
    }
    if (userAccount.length==0) {
        NSLog(@"用户名为空!");
        return 0;
    }
    NSLog(@"要插入的数据为:%@",arrServiceNoticeList);
    for (int i=0; i<[arrServiceNoticeList count]; i++) {
        NSMutableDictionary *dictItem=[arrServiceNoticeList objectAtIndex:i];
        NSString *strid;
        if ([dictItem valueForKey:@"id"]) {
            strid=[dictItem valueForKey:@"id"];
        }else{
            strid=@"";
        }

        if ([self deleteServiceNoticeData:strid withUserAccount:userAccount]) {
            NSLog(@"删除数据成功!");
        }
        else
        {
            NSLog(@"删除数据失败!");
        }
    }
    for (int i=0; i<[arrServiceNoticeList count]; i++) {
        NSMutableDictionary *dictItem=[arrServiceNoticeList objectAtIndex:i];
        NSString *strid;
        if ([dictItem valueForKey:@"id"]) {
            strid=[dictItem valueForKey:@"id"];
        }else{
            strid=@"";
        }
        NSString *stritemname;
        if ([dictItem valueForKey:@"itemname"]) {
            stritemname=[dictItem valueForKey:@"itemname"];
        }else
        {
            stritemname=@"";
        }
        NSString *stropen;
        if ([dictItem valueForKey:@"open"]) {
            stropen=[dictItem valueForKey:@"open"];
        }else
        {
            stropen=@"";
        }
        NSString *strremindtypecode;
        if ([dictItem valueForKey:@"remindtypecode"]) {
            strremindtypecode=[dictItem valueForKey:@"remindtypecode"];
        }else
        {
            strremindtypecode=@"";
        }
        
        NSString *SERVICE_NOTICE_Table=@"SERVICE_NOTICE";
        sqlite3_stmt *statement;
        
        NSString *replace = [NSString stringWithFormat:@"INSERT INTO %@ (id,itemname,open,remindtypecode,useraccount) VALUES (?,?,?,?,?)",SERVICE_NOTICE_Table];
        if (sqlite3_prepare_v2(database, [replace UTF8String], -1, &statement, nil)== SQLITE_OK)
        {
            sqlite3_bind_text(statement,1,[strid UTF8String],-1,NULL);
            sqlite3_bind_text(statement,2,[stritemname UTF8String],-1,NULL);
            sqlite3_bind_text(statement,3,[stropen UTF8String],-1,NULL);
            sqlite3_bind_text(statement,4,[strremindtypecode UTF8String],-1,NULL);
            sqlite3_bind_text(statement,5,[userAccount UTF8String],-1,NULL);
            
        }
        NSLog(@"%d",sqlite3_step(statement));
        
    }
    return 1;
}
-(BOOL)deleteServiceNoticeData:(NSString *)strID withUserAccount:(NSString *)userAccount
{
    NSString *tableDelete=@"SERVICE_NOTICE";
    NSString *sqlDelete=[NSString stringWithFormat:@"delete from %@ where id='%@' and userAccount='%@'",tableDelete,strID,userAccount];
	sqlite3_stmt *statement;
	
	int linkCode = sqlite3_prepare_v2(database, [sqlDelete UTF8String], [sqlDelete length], &statement, NULL);
	if (linkCode != SQLITE_OK) {
		return NO;
	}
	linkCode = sqlite3_step(statement);
	sqlite3_finalize(statement);
	if (linkCode != SQLITE_DONE) {
		return NO;
	}
	return YES;
}
-(NSMutableArray *)getServiceNoticeData:(NSString *)userAccount
{
    NSString *SERVICE_NOTICE_Table=@"SERVICE_NOTICE";
    if (userAccount.length==0) {
        userAccount=@"";
    }
    sqlite3_stmt *statement;
    NSString *select = [NSString stringWithFormat:@"SELECT * FROM %@ where userAccount='%@'",SERVICE_NOTICE_Table,userAccount];
    NSMutableArray *arrSerice=[[NSMutableArray alloc]init];
    if(sqlite3_prepare_v2(database, [select UTF8String], -1, &statement, nil)!=SQLITE_OK)
    {
        sqlite3_close(database);
        NSAssert(0,@"Error querying:%s", err);
    }
    while (sqlite3_step(statement)==SQLITE_ROW)
    {
        
        NSString *strid=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 0)];
        NSString *stritemname=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 1)];
        NSString *stropen=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 2)];
        NSString *strremindtypecode=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 3)];
        NSString *struseraccount=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 4)];
        
        NSMutableDictionary *dictService=[[NSMutableDictionary alloc]init];
        [dictService setObject:strid forKey:@"id"];
        [dictService setObject:stritemname forKey:@"itemname"];
        [dictService setObject:stropen forKey:@"open"];
        [dictService setObject:strremindtypecode forKey:@"remindtypecode"];
        [dictService setObject:struseraccount forKey:@"useraccount"];
        [arrSerice addObject:dictService];
        [dictService release];
    }
    NSLog(@"sqlite:count-%d",[arrSerice count]);
    NSLog(@"sqlite:arrSerice%@",arrSerice);
    return arrSerice;
}
-(BOOL)insertManufacturer:(NSMutableArray *)arrManufacturer
{
    if (!arrManufacturer)
	{
		NSLog(@"empty arrManufacturer!");
		return 0;
		if (![arrManufacturer count])
		{
			NSLog(@"illegal arrManufacturer!");
			return 0;
		}
	}
    if ([arrManufacturer count]<=0) {
        return 0;
    }
    NSLog(@"要插入的数据为:%@",arrManufacturer);
    for (int i=0; i<[arrManufacturer count]; i++) {
        NSMutableDictionary *dictItem=[arrManufacturer objectAtIndex:i];
        NSString *strmanufacturerCode;
        if ([dictItem valueForKey:@"manufacturerCode"]) {
            strmanufacturerCode=[dictItem valueForKey:@"manufacturerCode"];
        }else{
            strmanufacturerCode=@"";
        }
        
        if ([self deleteManufacturer:strmanufacturerCode]) {
            NSLog(@"删除数据成功!");
        }
        else
        {
            NSLog(@"删除数据失败!");
        }
    }
    for (int i=0; i<[arrManufacturer count]; i++) {
        NSMutableDictionary *dictItem=[arrManufacturer objectAtIndex:i];
        NSString *strmanufacturerCode;
        if ([dictItem valueForKey:@"manufacturerCode"]) {
            strmanufacturerCode=[dictItem valueForKey:@"manufacturerCode"];
        }else{
            strmanufacturerCode=@"";
        }
        NSString *strmanufacturerName;
        if ([dictItem valueForKey:@"manufacturerName"]) {
            strmanufacturerName=[dictItem valueForKey:@"manufacturerName"];
        }else
        {
            strmanufacturerName=@"";
        }
        
        NSString *CAR_MANUFACTUER_Table=@"CAR_MANUFACTUER";
        sqlite3_stmt *statement;
        
        NSString *replace = [NSString stringWithFormat:@"INSERT INTO %@ (manufacturerCode,manufacturerName) VALUES (?,?)",CAR_MANUFACTUER_Table];
        if (sqlite3_prepare_v2(database, [replace UTF8String], -1, &statement, nil)== SQLITE_OK)
        {
            sqlite3_bind_text(statement,1,[strmanufacturerCode UTF8String],-1,NULL);
            sqlite3_bind_text(statement,2,[strmanufacturerName UTF8String],-1,NULL);
            
        }
        NSLog(@"%d",sqlite3_step(statement));
        
    }
    return 1;
}

-(BOOL)deleteManufacturer:(NSString *)strmanufacturerCode
{
    NSString *tableDelete=@"CAR_MANUFACTUER";
    NSString *sqlDelete=[NSString stringWithFormat:@"delete from %@ where manufacturerCode='%@'",tableDelete,strmanufacturerCode];
	sqlite3_stmt *statement;
	
	int linkCode = sqlite3_prepare_v2(database, [sqlDelete UTF8String], [sqlDelete length], &statement, NULL);
	if (linkCode != SQLITE_OK) {
		return NO;
	}
	linkCode = sqlite3_step(statement);
	sqlite3_finalize(statement);
	if (linkCode != SQLITE_DONE) {
		return NO;
	}
	return YES;
}

-(NSMutableArray *)getManufacturer
{
    @autoreleasepool {
        NSString *CAR_MANUFACTUER_Table=@"CAR_MANUFACTUER";
        sqlite3_stmt *statement;
        NSString *select = [NSString stringWithFormat:@"SELECT * FROM %@",CAR_MANUFACTUER_Table];
        NSMutableArray *arrSerice=[[NSMutableArray alloc]init];
        if(sqlite3_prepare_v2(database, [select UTF8String], -1, &statement, nil)!=SQLITE_OK)
        {
            sqlite3_close(database);
            NSAssert(0,@"Error querying:%s", err);
        }
        while (sqlite3_step(statement)==SQLITE_ROW)
        {
            
            NSString *strmanufacturerCode=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 0)];
            NSString *strmanufacturerName=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 1)];
            
            NSMutableDictionary *dictService=[[NSMutableDictionary alloc]init];
            [dictService setObject:strmanufacturerCode forKey:@"manufacturerCode"];
            [dictService setObject:strmanufacturerName forKey:@"manufacturerName"];
            [arrSerice addObject:dictService];
            [dictService release];
        }
        NSLog(@"sqlite:count-%d",[arrSerice count]);
        NSLog(@"sqlite:arrSerice%@",arrSerice);
        return arrSerice;
    }
}

-(BOOL)insertBrand:(NSMutableArray *)arrBrand withManufacturerCode:(NSString *)manufacturerCode
{
    if (!arrBrand)
	{
		NSLog(@"empty arrBrand!");
		return 0;
		if (![arrBrand count])
		{
			NSLog(@"illegal arrBrand!");
			return 0;
		}
	}
    if ([arrBrand count]<=0) {
        return 0;
    }
    if (manufacturerCode.length==0) {
        NSLog(@"生产厂商代码为空!!!!!!!");
        return 0;
    }
    NSLog(@"要插入的数据为:%@",arrBrand);
    for (int i=0; i<[arrBrand count]; i++) {
        NSMutableDictionary *dictItem=[arrBrand objectAtIndex:i];
        NSString *strbrandCode;
        if ([dictItem valueForKey:@"brandCode"]) {
            strbrandCode=[dictItem valueForKey:@"brandCode"];
        }else{
            strbrandCode=@"";
        }
        
        if ([self deleteBrand:manufacturerCode withBrandCode:strbrandCode]) {
            NSLog(@"删除数据成功!");
        }
        else
        {
            NSLog(@"删除数据失败!");
        }
    }
    for (int i=0; i<[arrBrand count]; i++) {
        NSMutableDictionary *dictItem=[arrBrand objectAtIndex:i];
        NSString *strbrandCode;
        if ([dictItem valueForKey:@"brandCode"]) {
            strbrandCode=[dictItem valueForKey:@"brandCode"];
        }else{
            strbrandCode=@"";
        }
        NSString *strbrandName;
        if ([dictItem valueForKey:@"brandName"]) {
            strbrandName=[dictItem valueForKey:@"brandName"];
        }else
        {
            strbrandName=@"";
        }
        
        NSString *CAR_BRAND_Table=@"CAR_BRAND";
        sqlite3_stmt *statement;
        
        NSString *replace = [NSString stringWithFormat:@"INSERT INTO %@ (manufacturerCode,brandCode,brandName) VALUES (?,?,?)",CAR_BRAND_Table];
        if (sqlite3_prepare_v2(database, [replace UTF8String], -1, &statement, nil)== SQLITE_OK)
        {
            sqlite3_bind_text(statement,1,[manufacturerCode UTF8String],-1,NULL);
            sqlite3_bind_text(statement,2,[strbrandCode UTF8String],-1,NULL);
            sqlite3_bind_text(statement,3,[strbrandName UTF8String],-1,NULL);
            
        }
        NSLog(@"%d",sqlite3_step(statement));
        
    }
    return 1;
}

-(BOOL)deleteBrand:(NSString *)strmanufacturerCode withBrandCode:(NSString *)strbrandCode
{
    NSString *tableDelete=@"CAR_BRAND";
    NSString *sqlDelete=[NSString stringWithFormat:@"delete from %@ where manufacturerCode='%@' and brandCode='%@'",tableDelete,strmanufacturerCode,strbrandCode];
	sqlite3_stmt *statement;
	
	int linkCode = sqlite3_prepare_v2(database, [sqlDelete UTF8String], [sqlDelete length], &statement, NULL);
	if (linkCode != SQLITE_OK) {
		return NO;
	}
	linkCode = sqlite3_step(statement);
	sqlite3_finalize(statement);
	if (linkCode != SQLITE_DONE) {
		return NO;
	}
	return YES;
}

-(NSMutableArray *)getBrand:(NSString *)strmanufacturerCode
{
    @autoreleasepool {
        if (strmanufacturerCode.length==0) {
            NSLog(@"生产厂商代码为空!!!!!");
            //return nil;
        }
        NSString *CAR_BRAND_Table=@"CAR_BRAND";
        sqlite3_stmt *statement;
        NSString *select = [NSString stringWithFormat:@"SELECT * FROM %@ WHERE manufacturerCode='%@'",CAR_BRAND_Table,strmanufacturerCode];
        NSMutableArray *arrSerice=[[NSMutableArray alloc]init];
        if(sqlite3_prepare_v2(database, [select UTF8String], -1, &statement, nil)!=SQLITE_OK)
        {
            sqlite3_close(database);
            NSAssert(0,@"Error querying:%s", err);
        }
        while (sqlite3_step(statement)==SQLITE_ROW)
        {
            
            NSString *strmanufacturerCode=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 0)];
            NSString *strbrandCode=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 1)];
            NSString *strbrandName=[NSString stringWithUTF8String:(char*)sqlite3_column_text(statement, 2)];
            
            NSMutableDictionary *dictService=[[NSMutableDictionary alloc]init];
            [dictService setObject:strmanufacturerCode forKey:@"manufacturerCode"];
            [dictService setObject:strbrandCode forKey:@"brandCode"];
            [dictService setObject:strbrandName forKey:@"brandName"];
            [arrSerice addObject:dictService];
            [dictService release];
        }
        NSLog(@"sqlite:count-%d",[arrSerice count]);
        NSLog(@"sqlite:arrSerice%@",arrSerice);
        return arrSerice;
    }
}
@end
